package com.lihan.GetSeatInLib.Service.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Sort;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import com.lihan.GetSeatInLib.Domain.FloorModel;
import com.lihan.GetSeatInLib.Repository.FloorModelRository;
import com.lihan.GetSeatInLib.Service.FloorService;

@Service
public class FloorSerivceImpl implements FloorService{

	//注入相应的持久层
	@Autowired
	private FloorModelRository _floordao;
	
	//注入redis缓存操作对象
//	@Autowired
//	@Qualifier("redisTemplate")
//	private RedisTemplate<String, FloorModel> redis;
	
	@Override
	//@Cacheable(cacheNames = "AllFloorCache")
	public Set<FloorModel> getAllFloor() {
		
		List<FloorModel> list =  _floordao.findAll(Sort.by("ID"));
		
		Set<FloorModel> set = new HashSet<>();
		list.forEach(item->{
			set.add(item);
		});
		return set;
	}
	
	@Override
	//@Cacheable(cacheNames = "FloorCache",key = "#id")
	public FloorModel getFloorById(Integer id) {
		FloorModel floor = _floordao.getById(id);
		return floor;
	}

	@Override
	//@CachePut(cacheNames = "FloorCache",key="#floor.ID")
	public boolean UpdateFloor(FloorModel floor) {
		try {
			_floordao.save(floor);
			return true;
		} catch (Exception e) {
		}
		return false;
	}

	@Override
	public boolean DeleteFloorById(Integer id) {
		try {
			_floordao.deleteById(id);
			return true;
		}catch (Exception e) {
		}
		return false;
	}

	@Override
	//@CacheEvict(cacheNames = {"AllFloorCache"})
	public boolean CreateNewFloor(FloorModel floor) {
		if(_floordao.save(floor)!=null)
			return true;
		else
			return false;
		
	}
	

}
